//
// Created by QU on 24-9-23.
//

#ifndef RECVNODE_H
#define RECVNODE_H

#include "BaseNode.h"

class Node final : public BaseNode
{
public:
    using BaseNode::MAX_NODE_SIZE;
    using BaseNode::SerializedData;

    constexpr static uint16_t MAX_HEADER_SIZE = sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint16_t);
    constexpr static uint16_t MAX_PAYLOAD_SIZE = MAX_NODE_SIZE - MAX_HEADER_SIZE;

    explicit Node(uint16_t payload_len, uint8_t type_tag = 0, uint8_t msg_id = 0);
    explicit Node(const std::byte data[], uint16_t node_len); // 反序列化构造函数
    explicit Node(const SerializedData& serialized_data); // 反序列化构造函数

    // 复制控制
    Node(const Node& other);
    Node& operator=(const Node& other);
    Node(Node&& other) noexcept;
    Node& operator=(Node&& other) noexcept;

    [[nodiscard]] SerializedData serialize() const override;
    [[nodiscard]] static Node deserialize(const std::byte data[], uint16_t size);

    [[nodiscard]] const std::byte* getNodePayloadPointer() const noexcept override;
    [[nodiscard]] uint16_t getNodePayloadSize() const noexcept override;
    [[nodiscard]] uint16_t getNodeFullSize() const noexcept override;

    [[nodiscard]] uint8_t getTypeTag() const noexcept;
    [[nodiscard]] uint8_t getMsgId() const noexcept;

    friend std::ostream& operator<<(std::ostream& os, const Node& node);

    ~Node() noexcept override = default;

private:
    uint8_t m_type_tag;
    uint8_t m_msg_id;
};

#endif // RECVNODE_H
